// This is a snippet to get the profile type of the current user using Win32 API (or P/Invoke as it's called)
// Need a reference to:

System.ComponentModel
System.Runtime.InteropServices


--------------------------------------------------------------


//constants used
private const uint PT_LOCAL = 0;
private const uint PT_TEMPORARY = 1;
private const uint PT_ROAMING = 2;
private const uint PT_MANDATORY = 4;

//Win32 API needed
[DllImport("Userenv.dll", EntryPoint = "GetProfileType", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool GetProfileType(ref uint pdwflags);

/// <summary>
/// method for getting the type of profile loaded for the current user
/// </summary>
/// <returns></returns>
public string GetUserProfileType()
{
    //Declare our variable that will hold the result
    uint type = 0;
    string profileType = string.Empty;
    try
    {
        //Call the API and pass in the variable declared above
        if (GetProfileType(ref type))
        {
            //Check to see what the value of the variable is now
            switch (type)
            {
                case PT_LOCAL:
                    profileType = "Local Profile";
                    break;
                case PT_TEMPORARY:
                    profileType = "Temporary Profile";
                    break;
                case PT_ROAMING:
                    profileType = "Roaming Profile";
                    break;
                case PT_MANDATORY:
                    profileType = "Mandatory Profile";
                    break;
            }

            
        }
        else
            throw new Win32Exception(Marshal.GetLastWin32Error());
    }
    catch (Exception ex)
    {
        profileType = ex.Message;
    }
    return profileType;
}